//
//  UILableExtension.swift
//  GomroClient
//
//  Created by mac on 2020/4/22.
//  Copyright © 2020 cn.gomro.app. All rights reserved.
//

import Foundation
import UIKit


//MARK: - UILabel
extension UILabel {
    open override var canBecomeFirstResponder: Bool {
         return true
    }
     
    open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return super.canPerformAction(action, withSender: sender)
    }
    
    /// 查看信息详情
    /// - Parameter recognizer: UILongPressGestureRecognizer
    @objc open func showDetailsInfo(sender recognizer: UILongPressGestureRecognizer){
        
        if recognizer.state == .began {
            
            autoreleasepool {
                self.becomeFirstResponder()
                let menu = UIMenuController.shared
                
                let txtInfo = UIMenuItem.init()
                txtInfo.title = self.text ?? "暂无信息"
                
                menu.menuItems = [txtInfo]
                menu.setTargetRect(self.frame, in: self.superview!)
                
                if menu.isMenuVisible { return }
                menu.setMenuVisible(true, animated: true)
            }
            
        }
    }
}


//MARK: - YYLabel
extension YYLabel {
    open override var canBecomeFirstResponder: Bool {
         return true
    }
     
    open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return super.canPerformAction(action, withSender: sender)
    }
    
    /// 查看信息详情
    /// - Parameter recognizer: UILongPressGestureRecognizer
    @objc open func showDetailsInfo(sender recognizer: UILongPressGestureRecognizer){
        if recognizer.state == .began {
            
            autoreleasepool {
                self.becomeFirstResponder()
                let menu = UIMenuController.shared
                
                let txtInfo = UIMenuItem.init()
                txtInfo.title = self.text ?? "暂无信息"
                
                menu.menuItems = [txtInfo]
                menu.setTargetRect(self.frame, in: self.superview!)
                
                if menu.isMenuVisible { return }
                menu.setMenuVisible(true, animated: true)
            }
        }
    }
}
